<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>跨域</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    <!-- 
        Origin: 协议 + IP/域名 + 端口号  完全一致表示同源
        跨域  ->  不同源请求。同源策略主要限制 AJAX

        页面间互相访问 -> domain + iframe  => 主域相同/IP相同
    -->
    
    <h2>跨域.html</h2>

    <!-- <iframe src="./b.html" frameborder="0" class="ifr"></iframe> -->
    <!-- <iframe src="http://127.0.0.1:5500/22-AJAX/b.html" frameborder="0" class="ifr"></iframe> -->
    <iframe src="http://127.0.0.1:8080/b.html" frameborder="0" class="ifr"></iframe>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript">
        // 设置主域
        document.domain = "127.0.0.1";

        $(".ifr").on("load", function (){
            // this.contentDocument   嵌套页面的document对象
            // this.contentWindow  嵌套页面的window对象
            console.log(this.contentDocument);
            console.log(this.contentWindow.a);
        })
    </script>
</body>
</html>